package com.vecspace.dayu.code.ui.pojo;


import java.util.Date;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.vecspace.data.model.IdEntity;
import com.vecspace.data.model.RowMapper;
import com.vecspace.dayu.code.template.pojo.IPageComponent;

import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.annotations.Polymorphism;
import org.hibernate.annotations.PolymorphismType;
import org.hibernate.annotations.Type;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/** DAYU-页面树结构配置
 * @author wanghua
 */
@Entity
@Polymorphism(type = PolymorphismType.EXPLICIT)
@Table(name = "DAYU_CODE_UI_DATA_TREE")
public class DataTree implements IPageComponent, IdEntity, java.io.Serializable {

	private static final long serialVersionUID = -984758759491633129L;
	public DataTree(){
	}
	

	private Long id;
	/**逻辑ID*/
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name = "ID")
	public Long getId(){
		return id;
	}
	/**逻辑ID*/
	public void setId(Long value){
		this.id = value;
	}

	private Long tableId;
	/**数据表ID*/
	@Column(name = "TABLE_ID")
	public Long getTableId(){
		return tableId;
	}
	/**数据表ID*/
	public void setTableId(Long value){
		this.tableId = value;
	}
	
	private String platformType;//终端类型
	@Column(name = "PLATFORM_TYPE")
	public String getPlatformType() {
		return platformType;
	}
	public void setPlatformType(String platformType) {
		this.platformType = platformType;
	}

	private Boolean catalogAsync;
	/**目录是否异步加载*/
	@Column(name = "CATALOG_ASYNC")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getCatalogAsync(){
		return catalogAsync;
	}
	/**目录是否异步加载*/
	public void setCatalogAsync(Boolean value){
		this.catalogAsync = value;
	}

	private Boolean catalogEditable;
	/**目录是否可编辑*/
	@Column(name = "CATALOG_EDITABLE")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getCatalogEditable(){
		return catalogEditable;
	}
	/**目录是否可编辑*/
	public void setCatalogEditable(Boolean value){
		this.catalogEditable = value;
	}


	private Boolean showLeafNode;
	/**在树结构上显示叶子数据*/
	@Column(name = "SHOW_LEAF_NODE")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getShowLeafNode(){
		return showLeafNode;
	}
	/**在树结构上显示叶子数据*/
	public void setShowLeafNode(Boolean value){
		this.showLeafNode = value;
	}

	private Date createTime;
	/**记录创建时间*/
	@JsonIgnore(true)
	@Column(name = "CREATE_TIME")
	public Date getCreateTime(){
		return createTime;
	}
	/**记录创建时间*/
	public void setCreateTime(Date value){
		this.createTime = value;
	}
	@Transient
	@JsonIgnore(true)
	public String getCreateTimeStr(){
		if(createTime == null){
			return "";
		}
		String exp = "yyyy-MM-dd";
		String timestr = new java.text.SimpleDateFormat(exp).format(createTime);
		return timestr;
	}

	private String createUser;
	/**记录创建人ID*/
	@Column(name = "CREATE_USER")
	public String getCreateUser(){
		return createUser;
	}
	/**记录创建人ID*/
	public void setCreateUser(String value){
		this.createUser = value;
	}

	public void parseFrom(Map<String, Object> row){
		RowMapper rowMapper = new RowMapper(row);
		this.id = rowMapper.getLong("ID");
		this.tableId = rowMapper.getLong("TABLE_ID");
		this.platformType = rowMapper.getString("PLATFORM_TYPE");
		this.catalogAsync = rowMapper.getBoolean("CATALOG_ASYNC");
		this.catalogEditable = rowMapper.getBoolean("CATALOG_EDITABLE");
		this.showLeafNode = rowMapper.getBoolean("SHOW_LEAF_NODE");
		this.createTime = rowMapper.getDate("CREATE_TIME");
		this.createUser = rowMapper.getString("CREATE_USER");
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj == null)return false;
		if(id == null)return false;
		DataTree other = (DataTree)obj;
		return id.equals(other.id);
	}

	@Override
	public int hashCode() {
		if(id == null)return 0;
		return id.hashCode();
	}
}
